

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:my_flutter_app/main.dart';

class DemoLocalizations {

  DemoLocalizations(this.isZh);

  bool isZh = false;

  static DemoLocalizations of(BuildContext context) {
    return Localizations.of<DemoLocalizations>(context, DemoLocalizations);
  }

  String get title {
    return isZh ? 'Flutter 应用' : 'Flutter App';
  }
}

class DemoLocalizationsDelegate extends LocalizationsDelegate<DemoLocalizations> {

  const DemoLocalizationsDelegate();

  @override
  bool isSupported(Locale locale) => ['zh', 'en'].contains(locale.languageCode);

  @override
  Future<DemoLocalizations> load(Locale locale) {
    print('$MY_TAG_1 $locale');
    return SynchronousFuture<DemoLocalizations>(DemoLocalizations(locale.languageCode == 'zh'));
  }

  @override
  bool shouldReload(LocalizationsDelegate<DemoLocalizations> old) => false;

}